﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Xml.Serialization;
using ABC.Business.Models;
using ABC.Core.Configuration;
using ABC.Domain.Entities;
using ABC.Domain.Serialization;

namespace ABC.Controllers.ViewModels.My
{
    public class FinancialPolicyViewModel : BaseViewModel
    {
        public string Company { get; set; }

        public List<SelectListItem> ListForCompany { get; set; }

        public string Type { get; set; }

        public List<SelectListItem> ListForType { get; set; }

        public List<SelectListItem> ListForProduct { get; set; }

        public string Credit { get; set; }

        public List<SelectListItem> ListForCredit { get; set; }

        public bool IsArchive { get; set; }

        public List<PolicyItem> Finance { get; set; }

        public List<DictionaryItem> Rewards { get; set; }

        public List<DictionaryItem> Credits { get; set; }

        public List<DictionaryItem> SpecialPrograms { get; set; }

        public PolicyItem PolicyItem { get; set; }

        public int PageNumber { get; set; }

        public int PageCount { get; set; }

        public int PageSize { get; set; }

        public List<SelectListItem> ListForPageSize { get; set; }

        public FinancialPolicyViewModel()
        {
            var financeModel = IoC.Resolve<FinanceModel>();
            ListForCompany = new List<SelectListItem>();
            ListForType = new List<SelectListItem>();
            ListForCredit = new List<SelectListItem>();
            ListForPageSize = new List<SelectListItem>();
            ListForProduct = new List<SelectListItem>();
            Rewards = new List<DictionaryItem>();
            Credits = new List<DictionaryItem>();
            Finance = new List<PolicyItem>();
            ListForPageSize = new List<SelectListItem>
                                  {
                                      new SelectListItem {Text = "10", Value = "10"},
                                      new SelectListItem {Value = "30", Text = "30"},
                                      new SelectListItem {Text = "50", Value = "50"},
                                      new SelectListItem {Text = "Все", Value = "all"}
                                  };
            Credits = financeModel.GetCredits().Select(x => new DictionaryItem
                                                                {
                                                                    Id = x.Key,
                                                                    Name = x.Value,
                                                                    Value = "False"
                                                                }).ToList();
            SpecialPrograms = new List<DictionaryItem>();
            SpecialPrograms = financeModel.GetSpecialPrograms();
            Rewards = financeModel.GetRewards();
            ListForCompany =
                financeModel.GetInsuranceCompanies().Select(x => new SelectListItem { Value = x.Key, Text = x.Value }).
                    ToList();
            ListForType =
                financeModel.GetTypesOfInsurance().Select(x => new SelectListItem { Value = x.Key, Text = x.Value }).
                    ToList();
            ListForCredit = financeModel.GetCredits().Select(x => new SelectListItem { Value = x.Key, Text = x.Value }).
                ToList();
            ListForProduct = financeModel.GetProducts(ListForCompany.First().Value, ListForType.First().Value).Select(x => new SelectListItem { Value = x.Key, Text = x.Value }).
                ToList();
        }
    }
}
